<?php
namespace app\admin\model;

use think\Model;

class Banner extends Model
{
    protected $pk = 'banner_id';
    public static function getBanner()
    {
        $list = Banner::field(true)
            ->order('sort')
            ->select()->toArray();
        return $list;
    }
    //添加首页轮播
    public static function addBannerAttr($add,$list)
    {
        if (in_array($add['sort'],$list)){
            $res = false;
            $msg = '排序值重复';
        }else{
            try{
                $res = Banner::strict(true)->save($add);
                $msg = '成功';
            }catch (\Exception $e){
                $res = false;
                $msg = $e->getMessage();
            }
        }
        return [$res,$msg];
    }
    //修改首页轮播
    public static function editBannerAttr($edit,$list)
    {
        if (in_array($edit['sort'],$list)){
            $res = false;
            $msg = '排序值重复';
        }else{
            try{
                $res = Banner::update($edit);
                $msg = '修改成功';
            }catch (\Exception $e){
                $res = false;
                $msg = $e->getMessage();
            }
        }
        return [$res,$msg];
    }
    //删除首页轮播
    public static function delBannerAttr($get)
    {
        try{
            $res = Banner::destroy($get['id']);
            $msg = '删除成功';
        }catch (\Exception $e){
            $res = false;
            $msg = $e->getMessage();
        }
        return [$res,$msg];
    }



}